home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / osrc.arc / NRSUBR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-13  |  2.9 KB  |  148 lines

  1.  
  2. /* Functions for level 3 net/rom support */
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "timer.h"
  6. #include "ax25.h"
  7. #include "netrom.h"
  8. #include "lapb.h"
  9. #include <ctype.h>
  10.  
  11. char *getaxaddr(), *putaxaddr();
  12.  
  13. /* Convert a net/rom network header to host format structure
  14.  * Return -1 if error, 0 if OK
  15.  */
  16.  
  17. int
  18. ntohnr3(hdr,bpp)
  19. register struct nr3hdr *hdr ;    /* output structure */
  20. struct mbuf **bpp ;
  21. {
  22.     char buf[AXALEN] ;
  23.     char ttl ;
  24.     
  25.     if (pullup(bpp,buf,AXALEN) < AXALEN)
  26.         return -1 ;
  27.     getaxaddr(&hdr->source,buf) ;
  28.  
  29.     if (pullup(bpp,buf,AXALEN) < AXALEN)
  30.         return -1 ;
  31.     getaxaddr(&hdr->dest,buf) ;
  32.  
  33.     if (pullup(bpp,&ttl,1) != 1)
  34.         return -1 ;
  35.  
  36.     hdr->ttl = uchar(ttl) ;
  37.  
  38.     return 0 ;
  39. }
  40.  
  41. /* Convert a host-format net/rom level 3 header into an mbuf ready
  42.  * for transmission.
  43.  */
  44.  
  45. struct mbuf *
  46. htonnr3(hdr)
  47. register struct nr3hdr *hdr;
  48. {
  49.     struct mbuf *rbuf ;
  50.     register char *cp ;
  51.  
  52.     if (hdr == (struct nr3hdr *) NULL)
  53.         return NULLBUF ;
  54.  
  55.     /* Allocate space for return buffer */
  56.     if ((rbuf = alloc_mbuf(NR3HLEN)) == NULLBUF)
  57.         return NULLBUF ;
  58.  
  59.     rbuf->cnt = NR3HLEN ;
  60.  
  61.     /* Now convert */
  62.     cp = rbuf->data ;
  63.  
  64.     hdr->source.ssid &= ~E ;    /* source E-bit is always off */
  65.     hdr->dest.ssid |= E ;        /* destination E-bit always set */
  66.  
  67.     cp = putaxaddr(cp,&hdr->source) ;
  68.     cp = putaxaddr(cp,&hdr->dest) ;
  69.     *cp = hdr->ttl ;
  70.  
  71.     return rbuf ;
  72. }
  73.  
  74. /* Convert a net/rom routing broadcast destination subpacket from
  75.  * network format to a host format structure.  Return -1 if error,
  76.  * 0 if OK.
  77.  */
  78. int ntohnrdest(ds,bpp)
  79. register struct nr3dest *ds ;
  80. struct mbuf **bpp ;
  81. {
  82.     char buf[AXALEN] ;
  83.     char quality ;
  84.  
  85.     /* get destination callsign */
  86.     if (pullup(bpp,buf,AXALEN) < AXALEN)
  87.         return -1 ;
  88.     memcpy(ds->dest.call,buf,ALEN) ;
  89.     ds->dest.ssid = buf[ALEN] ;
  90.  
  91.     /* get destination alias */
  92.     if (pullup(bpp,ds->alias,ALEN) < ALEN)
  93.         return -1 ;
  94.     ds->alias[ALEN] = '\0' ;
  95.  
  96.     /* get best neighbor callsign */
  97.     if (pullup(bpp,buf,AXALEN) < AXALEN)
  98.         return -1 ;
  99.     memcpy(ds->neighbor.call,buf,ALEN) ;
  100.     ds->neighbor.ssid = buf[ALEN] ;
  101.  
  102.     /* get route quality */
  103.     if (pullup(bpp,&quality,1) < 1)
  104.         return -1 ;
  105.     ds->quality = uchar(quality) ;
  106.  
  107.     return 0 ;
  108. }
  109.  
  110. /* Convert a host-format net/rom destination subpacket into an
  111.  * mbuf ready for transmission as part of a route broadcast
  112.  * packet.
  113.  */
  114. struct mbuf *
  115. htonnrdest(ds)
  116. register struct nr3dest *ds ;
  117. {
  118.     struct mbuf *rbuf ;
  119.     register char *cp ;
  120.  
  121.     if (ds == (struct nr3dest *) NULL)
  122.         return NULLBUF ;
  123.  
  124.     /* Allocate space for return buffer */
  125.     if ((rbuf = alloc_mbuf(NRRTDESTLEN)) == NULLBUF)
  126.         return NULLBUF ;
  127.  
  128.     rbuf->cnt = NRRTDESTLEN ;
  129.  
  130.     cp = rbuf->data ;
  131.  
  132.     memcpy(cp,ds->dest.call,ALEN) ;
  133.     cp += ALEN ;
  134.     *cp++ = ds->dest.ssid ;
  135.  
  136.     memcpy(cp,ds->alias,ALEN) ;
  137.     cp += ALEN ;
  138.  
  139.     memcpy(cp,ds->neighbor.call,ALEN) ;
  140.     cp += ALEN ;
  141.     *cp++ = ds->neighbor.ssid ;
  142.  
  143.     *cp = uchar(ds->quality) ;
  144.  
  145.     return rbuf ;
  146. }
  147.  
  148.